﻿Imports System.Data.SqlClient

Public Class setAccessNet
    Inherits System.Web.UI.Page


    Dim con As New DBConnect
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'check if user signed in if not going back to login page 
        If Not Session.Item("UserIn").Equals("yes") Then
            Response.Redirect("default.aspx")
        End If

        Dim tuid As Integer = getTUID()
        If tuid <> 0 Then
            lblHeading.Text = "Enter correct 9 digit TU-ID to view Involvements"
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim SqlConnectString As String = con.SqlConnectString
        Dim myConnection As New SqlConnection(SqlConnectString)
        Dim myCommand As New SqlCommand()
        myCommand.CommandType = CommandType.StoredProcedure
        myCommand.CommandText = "SetStudentID"

        Dim inputParameter As New SqlParameter("@accessNet", Session("UserID"))
        inputParameter.Direction = ParameterDirection.Input
        myCommand.Parameters.Add(inputParameter)

        Dim inputParameter2 As New SqlParameter("@tuID", TextBoxTUID.Text)
        inputParameter2.Direction = ParameterDirection.Input
        myCommand.Parameters.Add(inputParameter2)

        con.doUpdateUsingCmdObj(myCommand)
        Response.Redirect("ViewStudentFromStudentSide.aspx")


    End Sub

    Private Function getTUID() As Integer
        Dim SqlConnectString As String = con.SqlConnectString
        Dim myConnection As New SqlConnection(SqlConnectString)
        Dim myCommand As New SqlCommand()
        myCommand.CommandType = CommandType.StoredProcedure
        myCommand.CommandText = "GetTUID"

        Dim inputParameter As New SqlParameter("@userID", Session("UserID"))
        inputParameter.Direction = ParameterDirection.Input
        myCommand.Parameters.Add(inputParameter)

        'returning value of 0 if not found 
        Dim returnParameter As New SqlParameter("@tuID", 0)
        returnParameter.Direction = ParameterDirection.Output
        myCommand.Parameters.Add(returnParameter)

        Return con.ExecScalarFunction(myCommand)

    End Function
End Class